package org.example.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;

/**
 * 向session域中共享数据
 */
@Controller
public class ScopeSessionController {
    @RequestMapping("/testSession")
    public String testSession(HttpSession session) {
        session.setAttribute("name", "xxx");
        return "success";
    }

    @RequestMapping("/testContext")
    public String testContext(HttpSession session) {
        ServletContext application = session.getServletContext();
        application.setAttribute("name", "yyy");
        return "success";
    }
}
